package com.sasac.test.api.factory;

import com.sasac.common.core.domain.R;
import com.sasac.test.api.RemoteTestService;
import com.sasac.test.api.model.TestDTO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 服务降级处理
 *
 * @author sasac
 */
@Component
public class RemoteTestFallbackFactory implements FallbackFactory<RemoteTestService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteTestFallbackFactory.class);


    @Override
    public RemoteTestService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteTestService() {
            @Override
            public R<TestDTO> getTestInfo(String name) {
                return R.fail(name + "获取用户失败:" + throwable.getMessage());
            }
        };
    }
}
